//
//  PersonalViewController.m
//  inquiry
//
//  Created by 高宇 on 2020/5/27.
//  Copyright © 2020 高宇. All rights reserved.
//

#define SCREEN_WIDTH  ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)

#import "PersonalViewController.h"
#import "PersonalView.h"
#import "CompleteViewController.h"
#import "GXToast.h"
#import "ULNetHelper.h"
#import "Interface.h"
#import "NSString+MD5.h"
#import "JsonObject.h"
#import "SheelViewController.h"

@interface PersonalViewController ()<PersonalDelegate>
@property (nonatomic, strong) UIScrollView *scrollView;

@property (nonatomic, strong) UIButton *button;
@property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) UITextField *mainlabel;
@property (nonatomic, strong) UILabel *sexLabel;
@property (nonatomic, strong) UIButton *boyButton;
@property (nonatomic, strong) UIButton *girlButton;
@property (nonatomic, strong) PersonalView *numView;
@property (nonatomic, strong) PersonalView *schoolView;
@property (nonatomic, strong) PersonalView *gradeView;
@property (nonatomic, strong) PersonalView *classView;
@property (nonatomic, strong) PersonalView *moneyView;
@property (nonatomic, strong) PersonalView *fatherView;
@property (nonatomic, strong) PersonalView *momView;
@property (nonatomic, strong) PersonalView *scoreView;
@property (nonatomic, strong) UILabel *gloryLabel;
@property (nonatomic, strong) UIView *gloryView;
@property (nonatomic, strong) UITextView *gloryMainLabel;
@property (nonatomic, assign) BOOL isBoy;  //性别选项

//存放接口数据
@property (nonatomic, strong) NSArray *schoolArr;
@property (nonatomic, strong) NSArray *gradeArr;
@property (nonatomic, strong) NSArray *classArr;
@end

@implementation PersonalViewController

//在页面出现的时候就将黑线隐藏起来
 -(void)viewWillAppear:(BOOL)animated
{
    //显示导航栏下面的线条
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = nil;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.isBoy = YES;
    
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(0, 0, 40, 30);
    [backButton setTitle:@" 返回" forState:UIControlStateNormal];
    [backButton setTitleColor:[UIColor colorWithRed:173/255.0 green:173/255.0 blue:189/255.0 alpha:1.0] forState:0];
    [backButton setImage:[[UIImage imageNamed:@"fanhui"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];

    [backButton addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    [self createUI];
    [self setUI];
    [self getData];
    [self bianji:NO];
    
}

//返回
- (void)backClick:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)createUI{
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 1240);
    [self.view addSubview:self.scrollView];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(30, 20, 150, 33)];
    label.text = @"个人资料";
    label.font = [UIFont systemFontOfSize:24];
    label.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
    [self.scrollView addSubview:label];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(SCREEN_WIDTH-90, 30, 58, 32);
    [button setTitle:@"编辑" forState:0];
    [button setTitleColor:[UIColor whiteColor] forState:0];
    button.backgroundColor = [UIColor colorWithRed:110/255.0 green:132/255.0 blue:238/255.0 alpha:1];
    button.layer.cornerRadius = 10;
    [button addTarget:self action:@selector(editClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.scrollView addSubview:button];
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button.layer.cornerRadius = 10;
    self.button.frame = CGRectMake(30, 74, SCREEN_WIDTH-60, 48);
    self.button.backgroundColor = [UIColor colorWithRed:248/255.0 green:248/255.0 blue:248/255.0 alpha:1.0];
    [self.scrollView addSubview:self.button];
    
    self.label = [[UILabel alloc] initWithFrame:CGRectMake(20, 13, 64, 22)];
    self.label.font = [UIFont systemFontOfSize:16];
    self.label.textColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0];
    self.label.text = @"姓名";
    [self.button addSubview:self.label];
    
    self.mainlabel = [[UITextField alloc] initWithFrame:CGRectMake(98, 13, self.button.frame.size.width-121, 22)];
    self.mainlabel.font = [UIFont systemFontOfSize:16];
    self.mainlabel.textColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0];
    self.mainlabel.text = @"金三胖";
    [self.button addSubview:self.mainlabel];
    
    self.sexLabel = [[UILabel alloc] initWithFrame:CGRectMake(49, CGRectGetMaxY(self.button.frame)+33, 64, 22)];
    self.sexLabel.font = [UIFont systemFontOfSize:16];
    self.sexLabel.textColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0];
    self.sexLabel.text = @"性别";
    [self.scrollView addSubview:self.sexLabel];
    
    self.boyButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.boyButton.frame =CGRectMake(CGRectGetMaxX(self.sexLabel.frame), self.sexLabel.frame.origin.y, 85, 22);
    [self.boyButton setImage:[UIImage imageNamed:@"checkbox／selected+normal"] forState:0];
    [self.boyButton setTitleColor:[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0] forState:0];
    [self.boyButton setTitle:@" 小帅哥" forState:0];
    [self.scrollView addSubview:self.boyButton];
    [self.boyButton addTarget:self action:@selector(sexClick:) forControlEvents:UIControlEventTouchUpInside];
    
    self.girlButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.girlButton.frame =CGRectMake(CGRectGetMaxX(self.boyButton.frame)+15, self.sexLabel.frame.origin.y, 85, 22);
    [self.girlButton setImage:[UIImage imageNamed:@"checkbox／unselected+normal"] forState:0];
    [self.girlButton setTitleColor:[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0] forState:0];
    [self.girlButton setTitle:@" 小美女" forState:0];
    [self.girlButton addTarget:self action:@selector(sexClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.girlButton setSelected:NO];
    [self.scrollView addSubview:self.girlButton];
    
    self.numView = [[PersonalView alloc] initWithFrame:CGRectMake(30, CGRectGetMaxY(self.sexLabel.frame)+33, SCREEN_WIDTH-60, 48)];
    self.numView.delegate = self;
    [self.scrollView addSubview:self.numView];
    
    self.schoolView = [[PersonalView alloc] initWithFrame:CGRectMake(30, CGRectGetMaxY(self.numView.frame)+20, SCREEN_WIDTH-60, 48)];
    self.schoolView.label.text = @"学校";
    self.schoolView.mainlabel.text = @"上海师太";
    self.schoolView.delegate = self;
    [self.scrollView addSubview:self.schoolView];
    
    self.gradeView = [[PersonalView alloc] initWithFrame:CGRectMake(30, CGRectGetMaxY(self.schoolView.frame)+20, SCREEN_WIDTH-60, 48)];
    self.gradeView.label.text = @"年级";
    self.gradeView.mainlabel.text = @"2020级";
    self.gradeView.delegate = self;
    [self.scrollView addSubview:self.gradeView];
    
    self.classView = [[PersonalView alloc] initWithFrame:CGRectMake(30, CGRectGetMaxY(self.gradeView.frame)+20, SCREEN_WIDTH-60, 48)];
    self.classView.label.text = @"班级";
    self.classView.mainlabel.text = @"05班";
    self.classView.delegate = self;
    [self.scrollView addSubview:self.classView];
    
    self.moneyView = [[PersonalView alloc] initWithFrame:CGRectMake(30, CGRectGetMaxY(self.classView.frame)+20, SCREEN_WIDTH-60, 48)];
    self.moneyView.label.text = @"家庭收入";
    self.moneyView.mainlabel.text = @"请选择";
    self.moneyView.delegate = self;
    [self.scrollView addSubview:self.moneyView];
    
    self.fatherView = [[PersonalView alloc] initWithFrame:CGRectMake(30, CGRectGetMaxY(self.moneyView.frame)+20, SCREEN_WIDTH-60, 48)];
    self.fatherView.label.text = @"父亲学历";
    self.fatherView.mainlabel.text = @"请选择";
    self.fatherView.delegate = self;
    [self.scrollView addSubview:self.fatherView];
    
    self.momView = [[PersonalView alloc] initWithFrame:CGRectMake(30, CGRectGetMaxY(self.fatherView.frame)+20, SCREEN_WIDTH-60, 48)];
    self.momView.label.text = @"母亲学历";
    self.momView.mainlabel.text = @"请选择";
    self.momView.delegate = self;
    [self.scrollView addSubview:self.momView];
    
    self.scoreView = [[PersonalView alloc] initWithFrame:CGRectMake(30, CGRectGetMaxY(self.momView.frame)+20, SCREEN_WIDTH-60, 48)];
    self.scoreView.label.text = @"学生成绩";
    self.scoreView.mainlabel.text = @"请选择";
    self.scoreView.delegate = self;
    [self.scrollView addSubview:self.scoreView];
    
    self.gloryLabel = [[UILabel alloc] initWithFrame:CGRectMake(33, CGRectGetMaxY(self.scoreView.frame)+40, SCREEN_WIDTH-60, 70)];
    self.gloryLabel.font = [UIFont systemFontOfSize:16];
    self.gloryLabel.textColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0];
    self.gloryLabel.numberOfLines = 0;
    self.gloryLabel.text = @"是否具有等级，技能或各类荣誉证书（钢琴乐器等级，书法绘画，志愿者，优秀学生等）";
    [self.scrollView addSubview:self.gloryLabel];
    
    self.gloryView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.gloryLabel.frame)+20, SCREEN_WIDTH, 150)];
    self.gloryView.backgroundColor = [UIColor colorWithRed:248/255.0 green:248/255.0 blue:248/255.0 alpha:1.0];
    [self.scrollView addSubview:self.gloryView];
    
    self.gloryMainLabel = [[UITextView alloc] initWithFrame:CGRectMake(33, 25, SCREEN_WIDTH-60, self.gloryView.frame.size.height-50)];
    self.gloryMainLabel.font = [UIFont systemFontOfSize:16];
    self.gloryMainLabel.backgroundColor = [UIColor clearColor];
    self.gloryMainLabel.textColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0];
    self.gloryMainLabel.text = @"年入百万，年入百万年入百万年入百万年入百万年入百万年入百万年入百万年入百万年入百万年入百万年入百万年入百万年入百万年入百万年入百万";
    [self.gloryView addSubview:self.gloryMainLabel];
    
    //重新设置contentSize
    self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, CGRectGetMaxY(self.gloryView.frame));
    
}

- (void)getData{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSInteger gradeId = [user integerForKey:@"gradeId"];
    NSInteger schoolId = [user integerForKey:@"schoolId"];
    NSInteger classesId = [user integerForKey:@"classesId"];
    
    dispatch_group_t group = dispatch_group_create();
    dispatch_group_async(group,dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // 追加任务1
        dispatch_group_enter(group);   //标志着一个任务追加到 group，执行一次，相当于 group 中未执行完毕任务数+1
        //网络请求无论成功或失败都需要调用dispatch_group_leave(group)方法任务数减一
        [ULNetHelper GET:schoolListPath parameters:nil success:^(id responseObject) {
            NSDictionary *dic = responseObject;
            long code = [dic[@"code"] longValue];
            if (code == 200) {
                NSMutableArray *array = [NSMutableArray array];
                NSArray *arr = dic[@"data"];
                for (NSDictionary *dic in arr) {
                    NSMutableDictionary *tempDic = [NSMutableDictionary dictionary];
                    [tempDic setValue:[NSString stringWithFormat:@"%@",dic[@"schoolId"]]  forKey:@"id"];
                    [tempDic setValue:dic[@"schoolName"] forKey:@"name"];
                    [array addObject:tempDic];
                    
                    if (schoolId == [tempDic[@"id"] intValue]) {
                        self.schoolView.idStr = tempDic[@"id"];
                        self.schoolView.mainlabel.text = dic[@"schoolName"];
                    }
                }
                self.schoolArr = array;
            }else{
                NSLog(@"学校列表请求失败");
            }
            dispatch_group_leave(group);  //标志着一个任务离开了 group，执行一次，相当于 group 中未执行完毕任务
        }];
    });

    dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // 追加任务2
        dispatch_group_enter(group);
        [ULNetHelper GET:gradesListPath parameters:nil success:^(id responseObject) {
            NSDictionary *dic = responseObject;
            long code = [dic[@"code"] longValue];
            if (code == 200) {
                NSMutableArray *array = [NSMutableArray array];
                NSArray *arr = dic[@"data"];
                for (NSDictionary *dic in arr) {
                    NSMutableDictionary *tempDic = [NSMutableDictionary dictionary];
                    [tempDic setValue:[NSString stringWithFormat:@"%@",dic[@"gradeId"]]  forKey:@"id"];
                    [tempDic setValue:dic[@"gradeName"] forKey:@"name"];
                    [array addObject:tempDic];
                    
                    if (gradeId == [tempDic[@"id"] intValue]) {
                        self.gradeView.idStr = tempDic[@"id"];
                        self.gradeView.mainlabel.text = dic[@"gradeName"];
                    }
                }
                self.gradeArr = array;
            }else{
                NSLog(@"年级列表请求失败");
            }
            dispatch_group_leave(group);
        }];
    });
    
    dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // 追加任务3
        dispatch_group_enter(group);
        [ULNetHelper GET:classesListPath parameters:nil success:^(id responseObject) {
            NSDictionary *dic = responseObject;
            long code = [dic[@"code"] longValue];
            if (code == 200) {
                NSMutableArray *array = [NSMutableArray array];
                NSArray *arr = dic[@"data"];
                for (NSDictionary *dic in arr) {
                    NSMutableDictionary *tempDic = [NSMutableDictionary dictionary];
                    [tempDic setValue:[NSString stringWithFormat:@"%@",dic[@"classesId"]] forKey:@"id"];
                    [tempDic setValue:dic[@"classesName"] forKey:@"name"];
                    [array addObject:tempDic];
                    
                    if (classesId == [tempDic[@"id"] intValue]) {
                        self.classView.idStr = tempDic[@"id"];
                        self.classView.mainlabel.text = dic[@"classesName"];
                    }
                }
                self.classArr = array;
            }else{
                NSLog(@"班级列表请求失败");
            }
            dispatch_group_leave(group);
        }];
    });
}

- (void)sexClick:(UIButton *)button{
    if (button == _boyButton) {
        if (button.selected) {
            [self.boyButton setImage:[UIImage imageNamed:@"checkbox／unselected+normal"] forState:0];
            [self.girlButton setImage:[UIImage imageNamed:@"checkbox／selected+normal"] forState:0];
            self.isBoy = NO;
        }else{
            [self.boyButton setImage:[UIImage imageNamed:@"checkbox／selected+normal"] forState:0];
            [self.girlButton setImage:[UIImage imageNamed:@"checkbox／unselected+normal"] forState:0];
            self.isBoy = YES;
        }
    }
    else if (button == _girlButton) {
        if (button.selected) {
            [self.boyButton setImage:[UIImage imageNamed:@"checkbox／selected+normal"] forState:0];
            [self.girlButton setImage:[UIImage imageNamed:@"checkbox／unselected+normal"] forState:0];
            self.isBoy = YES;
        }else{
            [self.boyButton setImage:[UIImage imageNamed:@"checkbox／unselected+normal"] forState:0];
            [self.girlButton setImage:[UIImage imageNamed:@"checkbox／selected+normal"] forState:0];
            self.isBoy = NO;
        }
    }
    button.selected = !button.selected;
}

- (void)bianji:(BOOL)isChange{
    self.mainlabel.enabled = isChange;
    self.boyButton.enabled = isChange;
    self.girlButton.enabled = isChange;
    self.numView.button.enabled = isChange;
    self.schoolView.button.enabled = isChange;
    self.classView.button.enabled = isChange;
    self.gradeView.button.enabled = isChange;
    self.moneyView.button.enabled = isChange;
    self.fatherView.button.enabled = isChange;
    self.momView.button.enabled = isChange;
    self.scoreView.button.enabled = isChange;
    self.gloryView.userInteractionEnabled = isChange;
}

- (void)editClick:(UIButton *)button{
    button.selected = !button.selected;
    if (button.selected) {
        [button setTitle:@"完成" forState:0];
    }else{
        button.enabled = NO;
        [button setTitle:@"编辑" forState:0];
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSString *uuid = [user objectForKey:@"uuid"];
        
        NSString *gradeId = self.gradeView.idStr;
        NSString *classesId = self.classView.idStr;
        NSString *schoolId = self.schoolView.idStr;
        NSString *studentName = self.mainlabel.text;
        NSString *gender;
        if (self.isBoy) {
            gender = @"man";
        }else{
            gender = @"woman";
        }
        
        NSDictionary *userInfo = @{
            @"gender":[JsonObject fuckNULL:gender],
            @"age":[JsonObject fuckNULL:self.numView.idStr],
            @"household_income":[JsonObject fuckNULL:self.moneyView.idStr],
            @"father_edu":[JsonObject fuckNULL:self.fatherView.idStr],
            @"mother_edu":[JsonObject fuckNULL:self.momView.idStr],
            @"academic_performance":[JsonObject fuckNULL:self.scoreView.idStr],
            @"other":[JsonObject fuckNULL:self.gloryMainLabel.text],
        };
        
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:NSJSONWritingPrettyPrinted error:nil];
        NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

        
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        dic[@"gradeId"] = gradeId;
        dic[@"classesId"] = classesId;
        dic[@"schoolId"] = schoolId;
        dic[@"uuid"] = uuid;
        dic[@"studentName"] = studentName;
        dic[@"userInfo"] = jsonString;
        
        [ULNetHelper POST:updateStudentInfoPath parameters:dic success:^(id responseObject) {
            button.enabled = YES;
            NSDictionary *dic = responseObject;
            long code = [dic[@"code"] longValue];
            if (code == 200) {
                [GXToast showText:@"个人资料修改完毕"];
                [user setObject:studentName forKey:@"studentName"];
                [user setInteger:[gradeId intValue] forKey:@"gradeId"];
                [user setInteger:[schoolId intValue] forKey:@"schoolId"];
                [user setInteger:[classesId intValue] forKey:@"classesId"];
                [user setObject:jsonString forKey:@"userInfo"];
                
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [self.navigationController popViewControllerAnimated:YES];
                });
            }else{
                NSString *msg = responseObject[@"msg"];
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"资料修改失败" message: msg preferredStyle:UIAlertControllerStyleAlert];
                [alert addAction:[UIAlertAction actionWithTitle:@"关闭" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
                    
                }]];
                [self presentViewController:alert animated:YES completion:nil];
                
            }
        } failure:^(NSError *error) {
            button.enabled = YES;
        }];
    }
    [self bianji:button.selected];
}

- (void)personalClick:(UIView *)personalView{
    NSArray *arr;
    if (personalView == _schoolView) {
        arr = _schoolArr;
    }else if(personalView == _gradeView) {
        arr = _gradeArr;
    }else if(personalView == _classView) {
        arr = _classArr;
    }else if(personalView == _numView) {
        NSMutableArray *array = [NSMutableArray array];
        
        for(int i = 0; i < 26; i++)
        {
            NSMutableDictionary *tempDic = [NSMutableDictionary dictionary];
            [tempDic setValue:[NSString stringWithFormat:@"%d",i]  forKey:@"id"];
            [tempDic setValue:[NSString stringWithFormat:@"%d",i]  forKey:@"name"];
            [array addObject:tempDic];
        }
        arr = array;
    }else if (personalView == _moneyView) {
        arr = @[@{@"name":@"0-8万",@"id":@"0-8"},
        @{@"name":@"9-15万",@"id":@"9-15"},
        @{@"name":@"16-32万",@"id":@"16-32"},
        @{@"name":@"32万以上",@"id":@"32+"}];
    }else if(personalView == _fatherView) {
        arr = @[@{@"name":@"初中及以下",@"id":@"junior high"},
        @{@"name":@"高中(中专)",@"id":@"senior middle"},
        @{@"name":@"大专",@"id":@"college"},
        @{@"name":@"大学本科",@"id":@"university undergraduate"},
        @{@"name":@"硕士研究生",@"id":@"master's degree"},
        @{@"name":@"博士及以上",@"id":@"doctor"},];
    }else if(personalView == _momView) {
        arr = @[@{@"name":@"初中及以下",@"id":@"junior high"},
        @{@"name":@"高中(中专)",@"id":@"senior middle"},
        @{@"name":@"大专",@"id":@"college"},
        @{@"name":@"大学本科",@"id":@"university undergraduate"},
        @{@"name":@"硕士研究生",@"id":@"master's degree"},
        @{@"name":@"博士及以上",@"id":@"doctor"},];
    }else if(personalView == _scoreView) {
        arr = @[@{@"name":@"年级前10%",@"id":@"10%"},
                @{@"name":@"年级前11%-30%",@"id":@"11%-30%"},
                @{@"name":@"年级前31%-50%",@"id":@"31%-50%"},
                @{@"name":@"年级前51%-70%",@"id":@"51%-70%"},
                @{@"name":@"年级前71%-90%",@"id":@"71%-90"},
                @{@"name":@"年级前91%-100%",@"id":@"91%-100%"},];
    }
    
    SheelViewController *vc = [[SheelViewController alloc] init];
    vc.arr = arr;
    [[UIApplication sharedApplication].keyWindow addSubview:vc.view];
    [self addChildViewController:vc];
    
    __typeof(&*vc) __weak weakVC = vc;
    vc.block = ^{
        [weakVC.view removeFromSuperview];
        [weakVC removeFromParentViewController];
    };
    
    PersonalView *perView = (PersonalView *)personalView;
    vc.tureblock = ^(NSDictionary *dic) {
        perView.mainlabel.text = dic[@"name"];
        perView.idStr = dic[@"id"];
        [weakVC.view removeFromSuperview];
        [weakVC removeFromParentViewController];
    };
}

- (void)setUI{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *studentName = [user objectForKey:@"studentName"];
    NSData *jsonData = [[user objectForKey:@"userInfo"] dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *userInfo = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
    
    self.mainlabel.text = studentName;
    NSString *genderStr = userInfo[@"gender"];
    if ([genderStr isEqualToString:@"woman"]) {
        [self sexClick:self.girlButton];
    }
    
    NSArray *moneyArr = @[@{@"name":@"0-8万",@"id":@"0-8"},
    @{@"name":@"9-15万",@"id":@"9-15"},
    @{@"name":@"16-32万",@"id":@"16-32"},
    @{@"name":@"32万以上",@"id":@"32+"}];
    NSString *moneyStr = userInfo[@"household_income"];
    for (NSDictionary *dic in moneyArr) {
        if ([moneyStr isEqualToString:dic[@"id"]]) {
            self.moneyView.idStr = dic[@"id"];
            self.moneyView.mainlabel.text = dic[@"name"];
            break;
        }
    }
    
    NSString *age = userInfo[@"age"];
    for(int i = 0; i < 26; i++)
    {
        if ([age intValue] == i) {
            self.numView.idStr = age;
            self.numView.mainlabel.text = age;
            break;
        }
    }
    
    NSArray *eduArr = @[@{@"name":@"初中及以下",@"id":@"junior high"},
    @{@"name":@"高中（中专）",@"id":@"senior middle"},
    @{@"name":@"大专",@"id":@"college"},
    @{@"name":@"大学本科",@"id":@"university undergraduate"},
    @{@"name":@"硕士研究生",@"id":@"master's degree"},
    @{@"name":@"博士及以上",@"id":@"doctor"},];
    NSString *father_eduStr = userInfo[@"father_edu"];
    NSString *mother_eduStr = userInfo[@"mother_edu"];
    for (NSDictionary *dic in eduArr) {
        if ([father_eduStr isEqualToString:dic[@"id"]]) {
            self.fatherView.idStr = dic[@"id"];
            self.fatherView.mainlabel.text = dic[@"name"];
        }
        if ([mother_eduStr isEqualToString:dic[@"id"]]) {
            self.momView.idStr = dic[@"id"];
            self.momView.mainlabel.text = dic[@"name"];
        }
    }
    
    NSArray *performanceArr = @[@{@"name":@"年级前10%",@"id":@"10%"},
    @{@"name":@"年级前11%-30%",@"id":@"11%-30%"},
    @{@"name":@"年级前31%-50%",@"id":@"31%-50%"},
    @{@"name":@"年级前51%-70%",@"id":@"51%-70%"},
    @{@"name":@"年级前71%-90%",@"id":@"71%-90"},
    @{@"name":@"年级前91%-100%",@"id":@"91%-100%"},];
    NSString *performanceStr = userInfo[@"academic_performance"];
    for (NSDictionary *dic in performanceArr) {
        if ([performanceStr isEqualToString:dic[@"id"]]) {
            self.scoreView.idStr = dic[@"id"];
            self.scoreView.mainlabel.text = dic[@"name"];
            break;
        }
    }
    
    self.gloryMainLabel.text = userInfo[@"other"];
}

@end
